package cz.proks.easyhelpdesk.gae.api.impl.ws;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import cz.proks.easyhelpdesk.api.HelpdeskApi;
import cz.proks.easyhelpdesk.api.config.Configuration;
import cz.proks.easyhelpdesk.api.exception.ApiException;
import cz.proks.easyhelpdesk.api.model.Helpdesk;

@Controller(Configuration.WS.HELPDESK_API)
@RequestMapping(Configuration.WS.HELPDESK_BASE_URL)
public class HelpdeskApiImpl extends BaseApiImpl<Helpdesk> implements HelpdeskApi {
    private final Logger log = LoggerFactory.getLogger(getClass());

	@Autowired
	@Qualifier(Configuration.Core.WS.HELPDESK_API)
	private HelpdeskApi coreApi;

	@Override
	protected HelpdeskApi getCoreApi() {
		return coreApi;
	}

    @Override    
    @RequestMapping(value = "/listForUser/{userId}", method = RequestMethod.GET)
    @ResponseBody
    public List<Helpdesk> listForUser(@PathVariable Long userId) throws ApiException {        
        log.debug("listForUser():: Start with userId '{}'", userId);
        
        List<Helpdesk> entityList = getCoreApi().listForUser(userId);        
        
        log.debug("listForUser():: Exit with {} entities", entityList != null ? entityList.size() : null);
        return entityList;
    }
}
